package mcweb.model.dao;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import mcweb.dto.MemberDTO;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

public class MemberDAOImpl implements IMemberDAO{

	private SqlMapClientTemplate sqlMapClientTemplate;
	
	
	public MemberDAOImpl() {
		super();
	}
	
	
	public MemberDAOImpl(SqlMapClientTemplate sqlMapClientTemplate) {
		super();
		this.sqlMapClientTemplate = sqlMapClientTemplate;
	}


	/* (non-Javadoc)
	 * @see mcweb.model.dao.IMemberDAO#addMember(mcweb.dto.MemberDTO)
	 */
	@Override
	public void addMember(MemberDTO dto) throws SQLException {
		System.out.println("dao check :" + dto);
		sqlMapClientTemplate.insert("member.addMember",dto);
	}

	/* (non-Javadoc)
	 * @see mcweb.model.dao.IMemberDAO#modifyEmployee(mcweb.dto.MemberDTO)
	 */
	@Override
	public Object modifyMember(MemberDTO dto) throws SQLException {
		return sqlMapClientTemplate.update("member.modifyMember",dto);
	}

	/* (non-Javadoc)
	 * @see mcweb.model.dao.IMemberDAO#deleteMemberById(java.lang.String)
	 */
	@Override
	public Object deleteMemberById(String id) throws SQLException {
		return sqlMapClientTemplate.delete("member.deleteMemberById",id);
	}

	/* (non-Javadoc)
	 * @see mcweb.model.dao.IMemberDAO#deleteMemberById(java.lang.String[])
	 */
	@Override
	public Object deleteMemberByIds(String[] list) throws SQLException {
		HashMap map = new HashMap();
		map.put("ids", list);
		return sqlMapClientTemplate.delete("member.deleteEmployeeByIds",map);
	}

	/* (non-Javadoc)
	 * @see mcweb.model.dao.IMemberDAO#selectMemberById(java.lang.String)
	 */
	@Override
	public MemberDTO selectMemberById(String id) throws SQLException {
		return (MemberDTO) sqlMapClientTemplate.queryForObject("member.selectMemberById",id);
	}

	/* (non-Javadoc)
	 * @see mcweb.model.dao.IMemberDAO#selectMemberByName(java.lang.String)
	 */
	@Override
	public List selectMemberByName(String id) throws SQLException {
		return sqlMapClientTemplate.queryForList("member.selectMemberByName",id);
	}

	/* (non-Javadoc)
	 * @see mcweb.model.dao.IMemberDAO#selectAllMember()
	 */
	@Override
	public List selectAllMember() throws SQLException {
		return sqlMapClientTemplate.queryForList("member.selectAllMember");
	}

	public Object createTmpPwd(Map map) throws SQLException{
		return sqlMapClientTemplate.insert("member.createTmpPwd",map);
	}
	
	public Object updateTmpPwd(String hashPwd) throws SQLException{
		return sqlMapClientTemplate.update("member.updateTmpPwd",hashPwd);
	}

	/* (non-Javadoc)
	 * @see mcweb.model.dao.IMemberDAO#setSqlMapClientTemplate(org.springframework.orm.ibatis.SqlMapClientTemplate)
	 */
	@Override
	public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {
		this.sqlMapClientTemplate = sqlMapClientTemplate;
	}
	
}
